﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UPNP.IO.ValueConverters
{
    /// <summary>
    /// milliseconds since midnight
    /// </summary>
    internal sealed class DeviceTimeConverter : IDeviceValueConverter
    {
        public Type ManagedType
        {
            get { return typeof(TimeSpan); }
        }

        public object FromDevice(string value)
        {
            return TimeSpan.FromMilliseconds(Convert.ToInt64(value));
        }

        public string ToDevice(object value)
        {
            if (value is TimeSpan)
            {
                return Convert.ToString(((long)((TimeSpan)value).TotalMilliseconds));
            }

            return Convert.ToString(Convert.ToUInt64(value));
        }
    }
}
